package com.timi_licai.timi_licai_account.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.timi_licai.timi_licai_account.R;
import com.timi_licai.timi_licai_account.model.BookBg;

import java.util.List;

/**
 * Created by Administrator on 2015/3/18.
 */
public class AddAccountBookBGAdapter extends BaseAdapter {
    private Context context;
    private List<BookBg> bgColorList;

    public AddAccountBookBGAdapter(Context context, List<BookBg> bgColorList) {
        this.context = context;
        this.bgColorList = bgColorList;
    }

    @Override
    public int getCount() {
        return bgColorList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_add_account_book_dialog_bg, parent, false);
        ImageView addBg = (ImageView) view.findViewById(R.id.add_book_bg);
        ImageView addBgFlag = (ImageView) view.findViewById(R.id.add_book_bg_flag);
        switch (position) {
            case 0:
                addBg.setBackgroundColor(Color.parseColor(bgColorList.get(position).getColor()));
                if (bgColorList.get(position).isSelected()) {
                    addBgFlag.setVisibility(View.VISIBLE);
                }
                break;
            case 1:
                addBg.setBackgroundColor(Color.parseColor(bgColorList.get(position).getColor()));
                if (bgColorList.get(position).isSelected()) {
                    addBgFlag.setVisibility(View.VISIBLE);
                }
                break;
            case 2:
                addBg.setBackgroundColor(Color.parseColor(bgColorList.get(position).getColor()));
                if (bgColorList.get(position).isSelected()) {
                    addBgFlag.setVisibility(View.VISIBLE);
                }
                break;
            case 3:
                addBg.setBackgroundColor(Color.parseColor(bgColorList.get(position).getColor()));
                if (bgColorList.get(position).isSelected()) {
                    addBgFlag.setVisibility(View.VISIBLE);
                }
                break;
            case 4:
                addBg.setBackgroundColor(Color.parseColor(bgColorList.get(position).getColor()));
                if (bgColorList.get(position).isSelected()) {
                    addBgFlag.setVisibility(View.VISIBLE);
                }
                break;
        }

        return view;
    }
}
